function [blinks,unique_blink_ids]=get_blinks(pupil_pos,nbr_iframes)
throw_away=[];
for vnd=1:length(nbr_iframes)-1
    throw_away(vnd)=sum(nbr_iframes(1:vnd));
end






% tmp_blinks1=diff(pupil_pos(1,:));
% tmp_blinks1(end+1:end+51)=tmp_blinks1(end);
% blink_arr1=[];
% cnt=1;
% for lnd=1:length(tmp_blinks1)
%     if tmp_blinks1(lnd)<-50
%         cur_up=find(tmp_blinks1(lnd+1:lnd+50)>50,1,'first');
%         if ~isempty(cur_up)
%             blink_arr1(cnt,1)=lnd;
%             blink_arr1(cnt,2)=lnd+cur_up+1;
%             cnt=cnt+1;
%         end
%     end
% end
% 
% tmp_blinks2=diff(pupil_pos(2,:));
% tmp_blinks2(end+1:end+51)=tmp_blinks2(end);
% blink_arr2=[];
% cnt=1;
% for lnd=1:length(tmp_blinks2)
%     if tmp_blinks2(lnd)>50
%         cur_up=find(tmp_blinks2(lnd+1:lnd+50)<-50,1,'first');
%         if ~isempty(cur_up)
%             blink_arr2(cnt,1)=lnd;
%             blink_arr2(cnt,2)=lnd+cur_up+1;
%             cnt=cnt+1;
%         end
%     end
% end
% 
% overlap_inds=find(logical(sum(ismember(blink_arr1,blink_arr2),2)));
% 
% overlap_arr=[];
% for bnd=1:length(overlap_inds)
%     cur_1=blink_arr1(overlap_inds(bnd),:);
%     cur_ind=find(logical(sum(ismember(blink_arr2,cur_1),2)));
%     cur_2=blink_arr2(cur_ind,:);
%     overlap_arr(bnd,1)=min([cur_1(1):cur_1(2) cur_2(1):cur_2(2)]);
%     overlap_arr(bnd,2)=max([cur_1(1):cur_1(2) cur_2(1):cur_2(2)]);
% end
% 
% overlap_1=find(logical(sum(ismember(blink_arr1,overlap_arr),2)));
% overlap_2=find(logical(sum(ismember(blink_arr2,overlap_arr),2)));
% blink_arr1(overlap_1,:)=[];
% blink_arr2(overlap_2,:)=[];
% 
% tmp_blinks=blink_arr1;
% tmp_blinks(end+1:end+size(blink_arr2,1),:)=blink_arr2;
% tmp_blinks(end+1:end+size(overlap_arr,1),:)=overlap_arr;
% 
% for bnd=1:length(throw_away)
%     check=ismember(tmp_blinks,throw_away(bnd)-10:throw_away(bnd)+10);
%     check=logical(sum(check,2));
%     if sum(check)>0
%         tmp_blinks(check,:)=[];
%     end
% end
% 
% res=sort(tmp_blinks);
% 
% unique_blink_ids=unique(res(:,1));
% 
% cnt=1;
% stop=0;
% while stop==0
%     cur_inds=res(cnt,1):res(cnt,2);
%     next_inds=res(cnt+1,1):res(cnt+1,2);
%     if length(unique([cur_inds next_inds]))~=(length(cur_inds)+length(next_inds))
%         res(cnt,:)=[min(unique([cur_inds next_inds])) max(unique([cur_inds next_inds]))];
%         res(cnt+1,:)=[];
%     else
%         cnt=cnt+1;
%     end
%     if size(res,1)==cnt
%         stop=1;
%     end
% end
% blinks=res;